package com.example.sxt_practise.IO;

import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;

/**
 * @author gaofeng
 * @date 2022年05月10日 21:14
 */
public class UrlTest {
    public static void main(String[] args) {
        File file = new File("baidu.html") ;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL("http://www.baidu.com").openStream(), StandardCharsets.UTF_8));
             BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));) {
            String temp ;
            while ((temp = reader.readLine()) != null) {
                writer.write(temp);
                writer.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
